package com.qf.controller;

import com.qf.service.DtsGoodsService;
import com.qf.service.DtsOrderService;
import com.qf.service.DtsStatService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import com.qf.vo.GoodsStatVo;
import com.qf.vo.OrderStatVo;
import com.qf.vo.UserStatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/admin/stat")
public class AdminStatController {

    @Autowired
    DtsUserService userService;
    @Autowired
    DtsGoodsService goodsService;
    @Autowired
    DtsOrderService orderService;

    @Autowired
    DtsStatService statService;

    @GetMapping("/goods")
    public Object goods(){
        List<GoodsStatVo> goods = statService.findDaysAndGoods();

        String[] columns = {"days","orders","products","amount"};

        Map<String,Object> data = new HashMap<>();
        data.put("columns",columns);
        data.put("rows",goods);

        return ResponseUtil.ok(data);

    }

    @GetMapping("/order")
    public Object order(){
        List<OrderStatVo> orders = statService.findDaysAndOrders();

        String[] columns = {"days","orders","customers","amount","pcr"};
        Map<String,Object> data = new HashMap<>();
        data.put("columns",columns);
        data.put("rows",orders);

        return ResponseUtil.ok(data);
    }

    @RequestMapping("/user")
    public Object user(){

        List<UserStatVo> users = statService.findDaysAndUsers();

        String[] columns = {"days","users"};
        Map<String,Object> data = new HashMap<>();
        data.put("columns",columns);
        data.put("rows",users);

        return ResponseUtil.ok(data);
    }

}
